<template>
    <van-sticky>
        <van-nav-bar title="订单商品" left-text="返回" left-arrow @click-left="onBack">
        </van-nav-bar>
    </van-sticky>

    <van-card v-for="item in CartList" :key="item.id" :num="item.pronum" @click="toProduct(item.products.id,item.attrs)">
        <template #thumb>
            <van-image width="88" height="88" fit="cover" :src="item.products.thumb_cdn" />
        </template>
        <template #title>
            <div>
                商品：{{ item.products.name }}
            </div>
        </template>

        <template #price>
            <div>
                花费价格：{{ item.total }}
            </div>
        </template>

        <template #tags>
            <van-tag plain type="danger" v-if="!item.attrs">无商品规格</van-tag>
            <div v-else>
                <van-tag plain type="primary" v-for="attr in JSON.parse(item.attrs)" :key="attr.id">{{ attr.value
                    }}</van-tag>
            </div>
        </template>

    </van-card>

</template>

<script setup>
const { proxy } = getCurrentInstance();

const CartList = ref([]);
const orderid = ref(proxy.$route.query.orderid ?? 0);
const business = ref(proxy.$cookies.get('business') ?? {});

onBeforeMount(() => {
    getCartListData();
})
const getCartListData = async () => {
    let params = {
        busid: business.value.id,
        orderid: orderid.value
    }

    let result = await proxy.$post({
        url: '/product/order/orderCt',
        params
    })
console.log(result.data);
    if (result.code === 1) {

        CartList.value = result.data;
        return false;

    } else {
        proxy.$NotifyWarn(result.msg);
        return false;
    }
}

//点击事件
const toProduct = (proid,attrs) => {
    proxy.$cookies.set('attrs',attrs);
    proxy.$router.push({ path: '/product/order/proComment', query: { proid,orderid:orderid.value } });
}
const onBack = () => proxy.$router.back();
</script>